﻿Imports System.Resources
Imports System.Threading
Imports Biz
Imports BLL
Imports DevComponents.DotNetBar


Public Class ctrlNuevaSeleccionPostulante
    Private _llamador As frmMainMetro
    Private _oSeleccion As cSeleccion
    Private _RM As ResourceManager


    Public Sub SetIdioma()

        _RM = New ResourceManager("UI.Idiomas", System.Reflection.Assembly.GetExecutingAssembly)

        btnAceptar.Text = _RM.GetString("btnAcpetar")
        btnCancelar.Text = _RM.GetString("btnCancelar")

        tabSeleccion1.Text = _RM.GetString("strSeleccionInicialUP")
        tabSeleccion2.Text = _RM.GetString("strSeleccionEtapaEntrevistasUP")
        tabSeleccion3.Text = _RM.GetString("strSeleccionPreliminarUP")
        tabSeleccion4.Text = _RM.GetString("strSeleccionFinalUP")

        advTreeSolicitudes_1.Columns("colPostu1_Numero").Text = _RM.GetString("strNumero")
        advTreeSolicitudes_1.Columns("colPostu1_Postulante").Text = _RM.GetString("strPostulante")
        advTreeSolicitudes_1.Columns("colPostu1_Tel").Text = _RM.GetString("strTelefono")
        advTreeSolicitudes_1.Columns("colPostu1_Mail").Text = _RM.GetString("strEMail")
        advTreeSolicitudes_1.Columns("colPostu1_FNac").Text = _RM.GetString("strFechaNacimiento")

        advTreeSolicitudes_2.Columns(0).Text = _RM.GetString("strNumero")
        advTreeSolicitudes_2.Columns(1).Text = _RM.GetString("strPostulante")
        advTreeSolicitudes_2.Columns(2).Text = _RM.GetString("strTelefono")
        advTreeSolicitudes_2.Columns(3).Text = _RM.GetString("strEMail")
        advTreeSolicitudes_2.Columns(4).Text = _RM.GetString("strFechaNacimiento")

        advTreeSolicitudes_3.Columns(0).Text = _RM.GetString("strNumero")
        advTreeSolicitudes_3.Columns(1).Text = _RM.GetString("strPostulante")
        advTreeSolicitudes_3.Columns(2).Text = _RM.GetString("strTelefono")
        advTreeSolicitudes_3.Columns(3).Text = _RM.GetString("strEMail")
        advTreeSolicitudes_3.Columns(4).Text = _RM.GetString("strFechaNacimiento")

        advTreeSolicitudes_4.Columns(0).Text = _RM.GetString("strNumero")
        advTreeSolicitudes_4.Columns(1).Text = _RM.GetString("strPostulante")
        advTreeSolicitudes_4.Columns(2).Text = _RM.GetString("strTelefono")
        advTreeSolicitudes_4.Columns(3).Text = _RM.GetString("strEMail")
        advTreeSolicitudes_4.Columns(4).Text = _RM.GetString("strFechaNacimiento")

        lblTituloForm.Text = _RM.GetString("strSeleccionarPostulantes")

    End Sub

    Public Property Llamador() As frmMainMetro
        Get
            Return _llamador
        End Get
        Set(value As frmMainMetro)
            _llamador = value
        End Set
    End Property

    Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
        _llamador.CloseModalPanel(Me, DevComponents.DotNetBar.Controls.eSlideSide.Left)
    End Sub

    Private Function ValidarForm() As Boolean
        Dim bValido As Boolean = True

        If tabSolicitudes.SelectedTab.Name = "tabSeleccion1" Then
            If advTreeSolicitudes_1.SelectedNodes.Count = 0 Then
                bValido = False
            End If
        End If

        If tabSolicitudes.SelectedTab.Name = "tabSeleccion2" Then
            If advTreeSolicitudes_2.SelectedNodes.Count = 0 Then
                bValido = False
            End If
        End If

        If tabSolicitudes.SelectedTab.Name = "tabSeleccion3" Then
            If advTreeSolicitudes_3.SelectedNodes.Count = 0 Then
                bValido = False
            End If
        End If

        If tabSolicitudes.SelectedTab.Name = "tabSeleccion4" Then
            If advTreeSolicitudes_4.SelectedNodes.Count = 0 Then
                bValido = False
            End If
        End If

        ValidarForm = bValido

    End Function

    Public Sub MostrarParaEdicion(oSeleccion As cSeleccion)

        lblMensajes.Text = ""

        _oSeleccion = oSeleccion

        LlenarForm(oSeleccion)

    End Sub

    Private Sub LlenarForm(oAux As cSeleccion)

        advTreeSolicitudes_1.Nodes.Clear()
        advTreeSolicitudes_2.Nodes.Clear()
        advTreeSolicitudes_3.Nodes.Clear()
        advTreeSolicitudes_4.Nodes.Clear()

        CargarGrilla1(oAux)
        CargarGrilla2(oAux)
        CargarGrilla3(oAux)
        CargarGrilla4(oAux)

        If advTreeSolicitudes_1.Nodes.Count > 0 Then advTreeSolicitudes_1.SelectedIndex = 0
        If advTreeSolicitudes_2.Nodes.Count > 0 Then advTreeSolicitudes_2.SelectedIndex = 0
        If advTreeSolicitudes_3.Nodes.Count > 0 Then advTreeSolicitudes_3.SelectedIndex = 0
        If advTreeSolicitudes_4.Nodes.Count > 0 Then advTreeSolicitudes_4.SelectedIndex = 0

        lblTituloSeleccion.Text = _oSeleccion.oTipo_Seleccion.TSel_Descrip

    End Sub

    Private Sub btnAceptar_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click
        Dim oAux As cSolicitud_Seleccion
        Dim nodeAux As DevComponents.AdvTree.Node


        If ValidarForm() Then

            If tabSolicitudes.SelectedTab.Name = "tabSeleccion1" Then
                For Each nodeAux In advTreeSolicitudes_1.SelectedNodes
                    oAux = New cSolicitud_Seleccion

                    oAux.Busq_Numero = _oSeleccion.oBusqueda.Busq_Numero
                    oAux.Sel_Numero = _oSeleccion.Sel_Numero
                    oAux.oSolicitud.Soli_Numero = Utils.Convert.ToInt16(nodeAux.Tag)
                    oAux.SolSel_Obs = ""

                    Try
                        If GestorSolicitud_Seleccion.Instance.Buscar(oAux) Is Nothing Then
                            GestorSolicitud_Seleccion.Instance.Ingresar(oAux)
                            GestorBitacora.Instance.Loguear(New cBitacora_Usuario(1, Utils.Enumeradores.Bitacora.SolicitudModificacion))
                        End If

                    Catch ex As Excepciones.Solicitud_SeleccionFalloBuscar
                        Main.ManejarExcepcion(ex)
                    Catch ex As Exception
                        Main.ManejarExcepcion(ex)
                    End Try
                Next
            End If

            _llamador.CloseModalPanel(Me, DevComponents.DotNetBar.Controls.eSlideSide.Left)
            _llamador.RefrescarGrillaSeleccion(_oSeleccion.oBusqueda.Busq_Numero)
        Else
            lblMensajes.Text = "No se seleccionaron solicitudes..."
        End If

    End Sub

    Public Sub CargarGrilla1(oSeleccion As cSeleccion)
        Dim oAux As cSolicitud
        Dim colObjetos As Collection
        Dim oNode As DevComponents.AdvTree.Node


        advTreeSolicitudes_1.BeginUpdate()

        advTreeSolicitudes_1.Nodes.Clear()

        Try
            colObjetos = GestorSolicitud.Instance.ConsultarPorBusqueda(_oSeleccion.oBusqueda)

            If Not colObjetos Is Nothing Then

                For Each oAux In colObjetos

                    oNode = New DevComponents.AdvTree.Node

                    oNode.Tag = oAux.Soli_Numero
                    oNode.Text = oAux.Soli_Numero
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oPostulante.Postu_NombreAp))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oPostulante.Postu_Telefono))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oPostulante.Postu_Mail))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oPostulante.Postu_FNac))

                    advTreeSolicitudes_1.Nodes.Add(oNode)

                Next
            End If

        Catch ex As Excepciones.Solicitud_SeleccionFalloConsultar
            Main.ManejarExcepcion(ex)
        Catch ex As Exception
            Main.ManejarExcepcion(ex)
        End Try

        advTreeSolicitudes_1.EndUpdate()

        advTreeSolicitudes_1.Refresh()

    End Sub

    Public Sub CargarGrilla2(oSeleccion As cSeleccion)
        Dim oAux As cSolicitud_Seleccion
        Dim colObjetos As Collection
        Dim oNode As DevComponents.AdvTree.Node


        advTreeSolicitudes_2.BeginUpdate()

        advTreeSolicitudes_2.Nodes.Clear()

        Try
            colObjetos = GestorSolicitud_Seleccion.Instance.ConsultarPorSeleccion(oSeleccion, 2)

            If Not colObjetos Is Nothing Then

                For Each oAux In colObjetos

                    oNode = New DevComponents.AdvTree.Node

                    oNode.Tag = oAux.oSolicitud.Soli_Numero
                    oNode.Text = oAux.oSolicitud.Soli_Numero
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_NombreAp))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_Telefono))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_Mail))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_FNac))

                    advTreeSolicitudes_2.Nodes.Add(oNode)

                Next
            End If

        Catch ex As Excepciones.Solicitud_SeleccionFalloConsultar
            Main.ManejarExcepcion(ex)
        Catch ex As Exception
            Main.ManejarExcepcion(ex)
        End Try

        advTreeSolicitudes_2.EndUpdate()

        advTreeSolicitudes_2.Refresh()

    End Sub

    Public Sub CargarGrilla3(oSeleccion As cSeleccion)
        Dim oAux As cSolicitud_Seleccion
        Dim colObjetos As Collection
        Dim oNode As DevComponents.AdvTree.Node


        advTreeSolicitudes_3.BeginUpdate()

        advTreeSolicitudes_3.Nodes.Clear()

        Try
            colObjetos = GestorSolicitud_Seleccion.Instance.ConsultarPorSeleccion(oSeleccion, 3)

            If Not colObjetos Is Nothing Then

                For Each oAux In colObjetos

                    oNode = New DevComponents.AdvTree.Node

                    oNode.Tag = oAux.oSolicitud.Soli_Numero
                    oNode.Text = oAux.oSolicitud.Soli_Numero
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_NombreAp))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_Telefono))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_Mail))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_FNac))

                    advTreeSolicitudes_3.Nodes.Add(oNode)

                Next
            End If

        Catch ex As Excepciones.Solicitud_SeleccionFalloConsultar
            Main.ManejarExcepcion(ex)
        Catch ex As Exception
            Main.ManejarExcepcion(ex)
        End Try

        advTreeSolicitudes_3.EndUpdate()

        advTreeSolicitudes_3.Refresh()

    End Sub

    Public Sub CargarGrilla4(oSeleccion As cSeleccion)
        Dim oAux As cSolicitud_Seleccion
        Dim colObjetos As Collection
        Dim oNode As DevComponents.AdvTree.Node


        advTreeSolicitudes_4.BeginUpdate()

        advTreeSolicitudes_4.Nodes.Clear()

        Try
            colObjetos = GestorSolicitud_Seleccion.Instance.ConsultarPorSeleccion(oSeleccion, 4)

            If Not colObjetos Is Nothing Then

                For Each oAux In colObjetos

                    oNode = New DevComponents.AdvTree.Node

                    oNode.Tag = oAux.oSolicitud.Soli_Numero
                    oNode.Text = oAux.oSolicitud.Soli_Numero
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_NombreAp))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_Telefono))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_Mail))
                    oNode.Cells.Add(New DevComponents.AdvTree.Cell(oAux.oSolicitud.oPostulante.Postu_FNac))

                    advTreeSolicitudes_4.Nodes.Add(oNode)

                Next
            End If

        Catch ex As Excepciones.Solicitud_SeleccionFalloConsultar
            Main.ManejarExcepcion(ex)
        Catch ex As Exception
            Main.ManejarExcepcion(ex)
        End Try

        advTreeSolicitudes_4.EndUpdate()

        advTreeSolicitudes_4.Refresh()

    End Sub

End Class
